package com.weavernorth.retailExperienceAward.service;

import com.weavernorth.retailExperienceAward.dto.dpxxInfo;
import com.weavernorth.retailExperienceAward.dto.dpxxVo;
import weaver.conn.RecordSet;
import weaver.general.Util;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: bruseewang
 * @Package: com.weavernorth.retailExperienceAward.service
 * @date: 2020/6/4 13:17
 * @description:
 */
public class dpxxRepositoryImpl implements dpxxRepository {
    @Override
    public dpxxVo getDpxx(String strQyjl) {
        RecordSet rs = new RecordSet();
        dpxxVo dpxx=new dpxxVo();
        dpxx.setQyjl(strQyjl);
        List<dpxxInfo> listInfo=new ArrayList<>();
        String strSql = "SELECT a.fgs,a.qyjl,a.ppkdx,a.dp,a.dpjb,a.dpzt,b.departmentname FROM uf_dpxx a LEFT JOIN hrmdepartment b ON  a.DP=b.ID INNER JOIN uf_cfdplstykh c ON a.fgs=c.fgsppdy WHERE  a.dpjb IN(2,3,4) and a.qyjl=" + strQyjl + " AND a.dp is NOT NULL ORDER BY a.fgs,a.dp asc";
        rs.executeQuery(strSql);
        while (rs.next()){
            //店铺级别
            String strRank = Util.null2String(rs.getString("dpjb"));
            //分公司
            String strfgs = Util.null2String(rs.getString("fgs"));
            //品牌
            String strBrand = Util.null2String(rs.getString("ppkdx"));
            //获取店铺状态
            String strStauts = Util.null2String(rs.getString("dpzt"));
            //dpmc:店铺ID
            String strDpId = Util.null2String(rs.getString("dp"));
            dpxxInfo dpxxInfo=new dpxxInfo();
            dpxxInfo.setQyjl(strQyjl);
            dpxxInfo.setDpjb(strRank);
            dpxxInfo.setFgs(strfgs);
            dpxxInfo.setPpkdx(strBrand);
            dpxxInfo.setDpzt(strStauts);
            dpxxInfo.setDp(strDpId);
            listInfo.add(dpxxInfo);
        }
        dpxx.setDpxxList(listInfo);
        return dpxx;
    }

    @Override
    public List<dpxxVo> getDpxxList() {
        RecordSet rs=new RecordSet();
        List<dpxxVo> list=new ArrayList<>();
        String strSqlQyjl = "SELECT a.qyjl FROM uf_dpxx a LEFT JOIN hrmdepartment b ON  a.DP=b.ID INNER JOIN uf_cfdplstykh c ON a.fgs=c.fgsppdy  WHERE a.dpjb IN(2,3,4) AND a.QYJL is NOT NULL GROUP BY a.QYJL";
        rs.executeQuery(strSqlQyjl);
        dpxxVo dpxx=null;
        while (rs.next()){
            String strQyjl= Util.null2String(rs.getString("qyjl"));
            dpxx=getDpxx(strQyjl);
            list.add(dpxx);
        }
        return list;
    }

}
